<?php

namespace App\Http\Controllers\Api;

use App\model\BadList;
use App\model\Dish;
use App\model\Drug;
use Dingo\Api\Http\Response\Format\Json;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Lib\Utils\ArrayUtils;

class ApiController extends Controller
{
/**
     * @SWG\Post(
     *     path="/api/getdruglist",
     *     summary="获取药品列表",
     *     tags={"Api"},
     *     @SWG\Parameter(name="key",in="formData",description="关键字", required=true,type="string"),
     *     @SWG\Response(
     *         response=200,
     *         description="It's ok"
     *     ),
     *     @SWG\Response(
     *         response="default",
     *         description="unexpected error"
     *     )
     * )
     */
    public function getdruglist(Request $request){
        $keywords=$request->input("key");
        return Drug::where("offical_name","like",'%'.$keywords.'%')
                     ->orWhere("normal_name","like",'%'.$keywords.'%')->get();
    }
    /**
     * @SWG\Post(
     *     path="/api/dishcheck",
     *     summary="获取药品列表",
     *     tags={"Api"},
     *     @SWG\Parameter(name="key",in="formData",description="关键字", required=true,type="string"),
     *     @SWG\Response(
     *         response=200,
     *         description="It's ok"
     *     ),
     *     @SWG\Response(
     *         response="default",
     *         description="unexpected error"
     *     )
     * )
     */
    public function dishcheck(Request $request){

        $keywords=json_decode($request->input("key"));
        return BadList::whereIn("material_1",$keywords)->whereIn("material_2",$keywords)->get();
    }
}
